#!/usr/bin/python
# -*- encoding: utf-8 -*-
'''
@File    :   4.py
@Time    :   2020/05/04 21:48:51
@Author  :   Malygos_l 
@Version :   1.0
@Contact :   751756061@qq.com
@WebSite :   www.gitee.com/malygos_l
'''
# (继续上面的练习) 模拟用户登录:
    #  5个同学的姓名,账号和密码(加密后的),保存在一个文件上;   系统提示,请输入登录同学姓名, 正确后,请输入账号, 正确后,提示请输入密码（输入明文）;  如果都正确,打印提示, 您登录成功(失败);
# Start typing your code from here

import hashlib
import os

try:
    with open("homework4/nup.txt","r",encoding = "UTF-8") as f:
        info = f.readlines()
        nupinfo = []
        for line in info:
            nupinfo.append(line.split())
        
        for i in range(5):
            if i == 0:
                n = input("请输入您的姓名：")
            if n == nupinfo[i][0]:
                u = input("请输入账号：")
                if u == nupinfo[i][1]:
                    p = input("请输入密码：")
                    md5 = hashlib.md5()
                    md5.update(p.encode("UTF-8"))
                    if md5.hexdigest() == nupinfo[i][2]:
                        print("您登录成功！")
                        break
                    else:
                        print("密码错误！")
                        break
                else:
                    print("账号错误！")
                    break
            elif i == 4:
                print("姓名错误！")

except IOError:
    print("ERROR!")